package charts.series.bars; 

class Sketch extends ElementBase {
	
	var outline:Float;
	var offset:Float;
	
	public function new( index:Float, style:Dynamic, group:Float ) {
		
		super( index, style, style.colour, style.tip, style.alpha, group );
		this.outline = style['outline-colour'];
		this.offset = style.offset;
	}
	
	
	public override function resize( sc:ScreenCoordsBase ):Void {
		
		var h:Dynamic = this.resize_helper( cast( sc, ScreenCoords) );
		
		// how sketchy the bar is:
		var offset:Int = this.offset;
		var o2:Int = offset/2;
		
		// fill the bar
		// number of pen strokes:
		var strokes:Int = 6;
		// how wide each pen will need to be:
		var l_width:Int = h.width/strokes;
		
		this.graphics.clear();
		this.graphics.lineStyle( l_width+1, this.colour, 0.85, true, "none", "round", "miter", 0.8 );
		for( i in 0...strokes)
		{
			this.graphics.moveTo( ((l_width*i)+(l_width/2))+(Math.random()*offset-o2), 2+(Math.random()*offset-o2) );
			this.graphics.lineTo( ((l_width*i)+(l_width/2))+(Math.random()*offset-o2), h.height-2+ (Math.random()*offset-o2) );
		}
		
		// outlines:
		this.graphics.lineStyle( 2, this.outline, 1 );
		// left upright
		this.graphics.moveTo( Math.random()*offset-o2, Math.random()*offset-o2 );
		this.graphics.lineTo( Math.random()*offset-o2, h.height+Math.random()*offset-o2 );
		
		// top
		this.graphics.moveTo( Math.random()*offset-o2, Math.random()*offset-o2 );
		this.graphics.lineTo( h.width+ (Math.random()*offset-o2), Math.random()*offset-o2 );
		
		// right upright
		this.graphics.moveTo( h.width+ (Math.random()*offset-o2), Math.random()*offset-o2 );
		this.graphics.lineTo( h.width+ (Math.random()*offset-o2), h.height+ (Math.random()*offset-o2) );
		
		// bottom
		this.graphics.moveTo( Math.random()*offset-o2, h.height+ (Math.random()*offset-o2) );
		this.graphics.lineTo( h.width+ (Math.random()*offset-o2), h.height+ (Math.random()*offset-o2) );
		
	}
}
